package com.aigestudio.demo.com.aigestudio.tabview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.aigestudio.demo.R;

/**
 * Created by Fcy on 2016/6/23.<br/>
 */
public class ArrowEditView extends RelativeLayout {

    private TextView tv_time;
    private View iv_arrow;
    private View line_bottom;

    private int mCurrEditState = -1;

    /**
     * 是否是编辑状态
     */
    //private boolean mIsEditState;
    public ArrowEditView(Context context) {
        super(context);
        init();
    }

    public ArrowEditView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    /**
     * 自己设置hint，颜色，大小等
     *
     * @return
     */
    public TextView getTextView() {
        return tv_time;
    }

    /**
     * 切换状态
     *
     * @param isEdit
     *         是否是编辑状态
     */
    public void changeState(boolean isEdit) {
        int state = isEdit ? 1 : 0;
        if (mCurrEditState != state) {
            mCurrEditState = state;
            iv_arrow.setVisibility(isEdit ? VISIBLE : GONE);
            line_bottom.setVisibility(isEdit ? VISIBLE : GONE);
            tv_time.getPaint().setFakeBoldText(!isEdit);
            tv_time.invalidate();
        }
    }

    public boolean isEditState() {
        return mCurrEditState == 1;
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.lib_edit_view, this, true);
        tv_time = (TextView) view.findViewById(R.id.tv_time);
        tv_time.setHint("请选择时间");
        iv_arrow = view.findViewById(R.id.iv_arrow);
        line_bottom = view.findViewById(R.id.line_bottom);
    }
}
